package com.eastone.user.serverapi.dao.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import com.eastone.user.serverapi.dao.InfoUserDao;
import com.eastone.user.serverapi.model.InfoUser;
import com.yjx.framework.dao.impl.CommonDaoImpl;
import com.yjx.framework.util.StrUtil;

@Repository("infoUserDao")
public class InfoUserDaoImpl extends CommonDaoImpl<InfoUser> implements InfoUserDao {
	private Map<String, Object> getSqlParameterMap(String userName, String userId, String phoneNum, String email,
			String sex) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userName", StrUtil.isBlank(userName) ? null : userName);
		map.put("userId", StrUtil.isBlank(userId) ? null : userId);
		map.put("phoneNum", StrUtil.isBlank(phoneNum) ? null : phoneNum);
		map.put("email", StrUtil.isBlank(email) ? null : email);
		map.put("sex", StrUtil.isBlank(sex) ? null : sex);
		return map;
	}

	@Override
	public List<InfoUser> getList(String userName, String userId, String phoneNum, String email, String sex, int pageNo,
			int pageSize) {
		List<InfoUser> resultList = getList(getSqlParameterMap(userName, userId, phoneNum, email, sex), pageNo,
				pageSize);
		if (resultList == null) {
			resultList = Collections.emptyList();
		}
		return resultList;
	}

	@Override
	public int getCount(String userName, String userId, String phoneNum, String email, String sex) {
		Integer result = getCount(getSqlParameterMap(userName, userId, phoneNum, email, sex));
		return result != null ? result.intValue() : 0;
	}
}
